#ifndef MSGSTRUCT_H
#define MSGTRUCT_H

#pragma once

#include "mdefines.h"
#include "sotdma.h"
#include "itdma.h"

namespace ns_yht
{

    struct ZDA
    {
        qint64 ctime;    // 当前时间，是本地时间,秒, SecsSinceEpoch
        qint64 zoneDiff; // 本地时间和utc的时间差，秒，ctime-utc
    };

    struct AIS_1
    {
        ForwardIndicator Repeat;
        int Mmsi{0};
        NavigationalState Status;
        int Rotais; // AIS报文中的转弯速率，127 = turning right at more than 5deg/30s (No TI available)； -127 = turning left at more than 5deg/30s (127 -127 128都是No TI available)
        int Rot;    // 实际的转弯速率。当Rotais !=127或-127 时，按公式计算： ROTais = 4.733 * SQRT(ROTsensor) degrees/min
        double Lon{181};
        double Lat{91};
        double COG{-1};
        double SOG{-1};
        int Accuracy;
        int Heading{-1};
        int UTCsecond{-1};
        ManeuverType Maneuver;
        RaimFlag Raim;
        Sotdma sotdma;
        Itdma itdma;
    };

    struct AIS_5
    {
        ForwardIndicator Repeat{ForwardIndicator::Default};
        int Mmsi;
        AISVersion AisVersion{AISVersion::Unknown};
        int IMONumber{0};
        QByteArray CallSign;
        QByteArray ShipName;
        int ShipType{0};
        int ToBow{0};       // 船头
        int ToStern{0};     // 船尾
        int ToPort{0};      // 左舷
        int ToStarboard{0}; // 右舷
        ElectronicDeviceTheType EDeviceTheType{ElectronicDeviceTheType::Defalut};
        int Month{0};
        int Day{0};
        int Hour{0};
        int Minute{0};
        double Draught{0.0};
        QByteArray DestinationName;
        DTEState DTE{DTEState::Default};
    };

    struct AIS_4
    {
        ForwardIndicator Repeat{ForwardIndicator::Default};
        int Mmsi;
        int Year{0};
        int Month{0};
        int Day{0};
        int Hour{0};
        int Minute{0};
        int Second{0};
        int Accuracy;
        double Lon;
        double Lat;
        ElectronicDeviceTheType electronicDeviceTheType{ElectronicDeviceTheType::Defalut};
        int control;
        RaimFlag Raim;
        Sotdma sotdma;
    };

    struct AIS_14
    {
        ForwardIndicator Repeat{ForwardIndicator::Default};
        int Mmsi;
        int partno;
        QString text;
    };

    struct AIS_18
    {
        ForwardIndicator Repeat{ForwardIndicator::Default};
        int Mmsi;
        double speed;
        int accuracy;
        double lon;
        double lat;
        double course;
        int heading;
        int second;
        int regional;
        int cs;
        int display;
        int dsc;
        int band;
        int msg22;
        int assigned;
        int raim;
        int radio;
    };

    struct AIS_21
    {
        ForwardIndicator Repeat{ForwardIndicator::Default};
        int Mmsi;
        int Type;
        QString Name;
        int Accuracy;
        double Lon;
        double Lat;
        int ToBow{0};
        int ToStern{0};
        int ToPort{0};
        int ToStarboard{0};
        ElectronicDeviceTheType electronicDeviceTheType{ElectronicDeviceTheType::Defalut};
        int UTCsecond;
        int Pianyi;
        int AtoNState;
        RaimFlag Raim;
        int trueAtoN;
        int Mode;
        int Remain;
    };

    struct AIS_24
    {
        ForwardIndicator Repeat{ForwardIndicator::Default};
        int Mmsi;
        int partno;
        QString shipname;
        int shiptype;
        QString vendorid;
        int model;
        int serial;
        QString callsign;
        int to_bow;
        int to_stern;
        int to_port;
        int to_starboard;
        ElectronicDeviceTheType EDeviceTheType{ElectronicDeviceTheType::Defalut};
    };

    struct HDG
    {
        double heading;
        double cicha;
        double zicha;
    };

    struct DPT
    {
        double depth;
        double offset;
        double maxrange;
    };

    struct ALR
    {
        QString ctime; // 当前时间，是本地时间,秒
        int id;
        AlarmCondition alarmCondition{AlarmCondition::Unknown};
        AlarmAcknowledgeState alarmAcknowledgeState{AlarmAcknowledgeState::Unknown};
        QString text;
    };

    struct GGA
    {
        int status;
        int type;
        qint64 utc;
        double lat;
        double lon;
        QString modeindicator;
        int satellitecount;
        double hdop;
        double altitude;
        QString altitudeunit;
        int heightanomaly;
        int heightanomalyunit;
        int difference;
        QString differenceid;
    };

    struct GNS
    {
        int type;
        qint64 utc;
        double lat;
        QString latdirection;
        double lon;
        QString londirection;
        ModeIndicator mode;
        int satellitecount;
        double hdop;
        double altitude;
        double geosep;
        double difference;
        double differenceid;
        QString status;
    };

    struct GLL
    {
        int type;
        double lat;
        double lon;
        qint64 utc;
        QString status;
        QString modeindicator;
    };

    struct RMC
    {
        int type;
        qint64 utc;
        QString status;
        double lat;
        double lon;
        double speed;
        double course;
        double declination;
        QString declinationdirection;
        QString modeindicator;
    };

    struct VTG
    {
        int type;
        double course;
        QString courseindicator;
        double coursemagnetic;
        QString coursemagneticindicator;
        double speed;
        QString speedunit;
        double speedkm;
        QString speedkmunit;
        QString modeindicator;
    };

    struct RMB
    {
        int type;
        QString status;
        double crosstrack;
        QString steeldirection;
        int originid;
        int destinationid;
        int lat;
        QString latdirection;
        int lon;
        QString londirection;
        double distance;
        double bearing;
        double speed;
        QString arrivalstatus;
        QString modeindicator;
    };

    struct TCI
    {
        quint64 sendId;    // 发信方 ID
        quint64 receiveId; // 收信方 ID
        int lf;            // 频点 1-S1  2-S2C   3-预留   4-B2d
        int time;          // 发送的utc时间,秒
        int codeType;      // 编码类别,0：汉字；1：代码；2：汉字与 ASCII 码混合
        int dataId;        // 数据标识,0：即时，1：邮箱
        QString msg;       // 通信数据,编码类别为“0”时，传输内容为计算机内
                           //         码，每个汉字 16bit，高位在前；编码类
                           //         别为“1”时，传输内容为 BCD 码字符；编
                           //         码类别为“2”时，汉字代码混合，通信
                           //         数据首字母固定为“A4”，按先后顺序
                           //         每 4bit 截取一次，转换成 16 进制数，每
                           //         个 16 进制数以 ASCII 的形式表示。如数
                           //         据长度不是 4bit 的整数倍，高位补 0，凑
                           //         成整数倍。这里存放已经解析好的内容
    };

    struct TTM
    {
        int id{0};            // 批号，0-999
        double distance{-1};  // 距离  米
        double bearing{-1};   // 舷角
        double dcpa{-1};      // DCPA  米
        double tcpa{-1};      // TCPA
        double speed{-1};     // 速度    节
        double course{-1};    // 航向
        QString name;         // 名称
        int status{0};        // 0:丢失 1:查询 2:跟踪中
        bool refrence{false}; // 是否是参考目标
        QString time;         // hhmmss.ss
    };

    struct TLL
    {
        int id{0};            // 批号，0-999
        double lat{91};       // 纬度
        double lon{361};      // 经度
        QString name;         // 名称
        QString time;         // hhmmss.ss
        int status{0};        // 0:丢失 1:查询 2:跟踪中
        bool refrence{false}; // 是否是参考目标
    };

} // namespace ns_yht
#endif